﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace LTP.Common
{
    public class SWFConverter
    {
        public bool Convert(string source, string output)
        {
            if (File.Exists(source))
            {
                Process pc = new Process();
                //ProcessStartInfo psi = new ProcessStartInfo(ConfigHelper.GetConfigString("PDFToSWF"),
                //    source + " -o " + output + " -T 9");
                //pc.StartInfo.UserName = ConfigHelper.GetConfigString("ServerName");
                //string pwd = ConfigHelper.GetConfigString("ServerPwd");
                //System.Security.SecureString ss = new System.Security.SecureString();
                //foreach (char c in pwd)
                //{
                //    ss.AppendChar(c);
                //}
                //pc.StartInfo.Password = ss;
                pc.StartInfo.FileName = ConfigHelper.GetConfigString("PDFToSWF");
                pc.StartInfo.Arguments = source + " -o " + output + " -T 9";
                pc.StartInfo.WorkingDirectory = "";
                pc.StartInfo.CreateNoWindow = true;
                pc.StartInfo.UseShellExecute = false;
                pc.StartInfo.RedirectStandardInput = false;
                pc.StartInfo.RedirectStandardOutput = true;
                pc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                //pc.StartInfo = psi;
                pc.Start();
                pc.WaitForExit();
                pc.Close();
                if (File.Exists(output))
                    return true;
                else
                    return false;
            }
            else
            {
                throw new Exception("没有找到要转换的文件");
            }
        }
    }
}
